package ycl.scheduled.common.utils;

import io.github.biezhi.ome.OhMyEmail;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import ycl.scheduled.common.properties.EmailProperties;

import javax.annotation.Resource;

/**
 * 邮箱工具
 *
 * @author: YCL
 * @date: 2021-10-26 11:02:46
 */
@Slf4j
@Component
public class EmailUtil {

	@Resource
	private EmailProperties emailProperties;

	/**
	 * 发送邮件
	 * @param user 对方邮箱
	 * @param title 标题
	 * @param content 内容
	 */
	public void sendEmail(String user, String title, String content) {
		try {
			OhMyEmail.config(
					OhMyEmail.SMTP_QQ(false),
					emailProperties.getUsername(),
					emailProperties.getPassword());
			OhMyEmail.subject(title)
					.from(emailProperties.getUsername())
					.to(user)
					.html(content).send();
		} catch (Exception e) {
			log.info(e.getMessage(), e);
		}
	}
}
